function initbody(){
	ind.init();
}
js.onkeydown = function(code){
	if(code==27)closetabsnow();
}
var ind = {
	init:function(){
		opentabs= [];
		tabsarr = {};
		objcont = $('#content_allmainview');
		objtabs = $('#tabs_title');
		
		$(window).resize(this.resize);
		this.resize();
		
		var homers = {name:'首页',num:'home',url:'adminhome,index',hideclose:true}
		addtabs(homers);
	},
	resize:function(){
		viewheight = winHb(); //可操作高度
		var obj = $('div[resizeh]'),o,hei;
		for(var i=0;i<obj.length;i++){
			o = $(obj[i]);
			hei=parseInt(o.attr('resizeh'));
			o.css('height',''+(viewheight-hei)+'px');
		}
		var _lw = 0;
		if(get('leftdiv')){
			_lw = $('#leftdiv').width();
			if(get('leftdiv').style.display=='none'){
				_lw = 0;
			}
		}
		var w = winWb()-_lw;
		viewwidth  = w;
		$('#indexcontent').css({width:''+viewwidth+'px'});
	},
	hideleft:function(){
		$('#leftdiv').toggle();
		this.resize();
	},
	menuhide:function(id){
		$('#menulist_'+id+'').toggle();
	},
	menuclick:function(id,na,url,bh){
		if(!bh)bh='menu'+id+'';
		var can = {name:na,num:bh,url:url};
		addtabs(can);
	},
	geren:function(){
		addtabs({name:'个人中心','url':'geren,view',num:'geren'});
	},
	editface:function(){
		js.updateface('修改头像','', function(lj){
			if(get('myfaces'))get('myfaces').src = lj;
			if(get('myface'))get('myface').src = lj;
			js.ajax.get('?m=geren&a=save&fields=face&value='+jm.base64encode(lj)+'');
		});
	},
	listopen:function(bh,na){
		var can = {name:na,num:bh,url:'input,list,num='+bh+''};
		addtabs(can);
	}
}

function loginexit(){
	js.confirm('确定要退出吗？',function(jg){
		if(jg=='yes'){
			js.loading('退出中...');
			js.ajax.get('?m=geren&a=exitcheck', function(){
				js.show.success('退出成功');
				js.reload();
			});
		}
	});
}

//添加选择卡
function addtabs(a){
	if(!a.num)a.num = js.getrand();
	var url = a.url,num	= a.num;
	if(isempt(url))return false;
	
	if(num=='mobile'){
		js.open(url,320,500);
		return;
	}
	if(url.indexOf('?')==0){
		window.open(url);
		return;
	}
	nowtabs = a;
	if(changetabs(num)){
		if(a.onShow)a.onShow();
		return true;
	}
	var s = '<li temp="tabs" nowrap onclick="changetabs(\''+num+'\',1)" id="tabs_'+num+'" class="active"><font>';
	if(a.icons)s+='<i class="icon-'+a.icons+'"></i>  ';
	s+=a.name+'</font>';
	if(!a.hideclose)s+='<span onclick="closetabs(\''+num+'\')">x</span>';
	s+='</li>';
	objtabs.append(s);
	
	var rand = js.getrand(),i,oi=2,
		ura	= url.split(','),
		mode= ura[0],
		act = ura[1];
	var gourl ='?m='+mode+'&a='+act+'';

	var urlpms= {rand:rand,viewmain:'content_'+num+''},urlcsn='';
	for(i=oi;i<ura.length;i++){
		var nus	= ura[i].split('=');
		urlpms[nus[0]] = nus[1];
		urlcsn += '&'+nus[0]+'='+nus[1]+'';
	}
	objcont.append('<div temp="content" id="content_'+num+'"><div style="padding-top:50px">'+js.ling(30)+'</div></div>');
	$.ajax({
		url:''+gourl+''+urlcsn+'&rand='+rand+'',
		type:'get',
		success: function(da){
			var s = da;
				s = s.replace(/\{rand\}/gi, rand);
			var obja = $('#content_'+num+'');
			obja.html(s);
			ind.resize();
			if(s.indexOf('clickevt')>0)importjs(''+mode+'_class',act, urlpms);
		},
		error:function(){
			var s = 'Error:加载出错喽,'+url+'';
			$('#content_'+num+'').html(s);
		}
	});
	tabsarr[num] = a;
	return false;
}

var coloebool = false,tabsnum='';
function closetabs(num){
	tabsarr[num] = false;
	$('#content_'+num+'').remove();
	$('#tabs_'+num+'').remove();
	if(num == nowtabs.num){
		var now ='home',i,noux;
		for(i=opentabs.length-1;i>=0;i--){
			noux= opentabs[i];
			if(get('content_'+noux+'')){
				now = noux;
				break;
			}
		}
		changetabs(now);
	}
	coloebool = true;
	setTimeout('coloebool=false',10);
}

function changetabs(num,lx){
	tabsnum = num;
	if(coloebool)return;
	if(!lx)lx=0;
	$("div[temp='content']").hide();
	$("[temp='tabs']").removeClass();
	var bo = false;
	if(get('content_'+num+'')){
		$('#content_'+num+'').show();
		$('#tabs_'+num+'').addClass('active');
		nowtabs = tabsarr[num];
		if(typeof(nowtabs.onshow)=='function')nowtabs.onshow();
		bo = true;
	}
	opentabs.push(num);
	return bo;
}

function closetabsnow(){
	if(tabsnum=='home')return;
	closetabs(tabsnum);
}